package tt.dz.mvc.controller.sys;

import com.alibaba.fastjson.JSON;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import tt.dz.entity.base.JsonCommon;
import tt.dz.entity.base.JsonForList;
import tt.dz.entity.system.OmsUrlList;
import tt.dz.entity.system.OmsUrlTreeVO;
import tt.dz.mvc.controller.base.BaseAction;
import tt.dz.mvc.controller.base.BaseController;
import tt.dz.service.sys.UrlListService;
import tt.dz.util.ActionUtils;
import tt.dz.util.OmsConstant;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Controller
@RequestMapping("url")
public class UrlController extends BaseController
{
	private Log log = LogFactory.getLog(UrlController.class);

	@Autowired
	private UrlListService urlListServiceImpl;

	@RequestMapping(value = "getAllUrls")
	@ResponseBody
	public JsonCommon<OmsUrlTreeVO> getAllUrls()
	{
		OmsUrlTreeVO tree = urlListServiceImpl.getAllUrlTree();
		return new JsonCommon<>(tree, OmsConstant.SuccessCodeEnum.SuccessCode.value(), OmsConstant.SuccessCodeEnum.SuccessCode.desc());
	}

	@RequestMapping(value = "updateUrls")
	@ResponseBody
	public JsonCommon updateUrls(String originTree, String updatedTree)
	{
		OmsUrlTreeVO originTreeVO = JSON.parseObject(originTree, OmsUrlTreeVO.class);
		OmsUrlTreeVO updatedTreeVO = JSON.parseObject(updatedTree, OmsUrlTreeVO.class);
		urlListServiceImpl.updateUrls(originTreeVO, updatedTreeVO);
		return new JsonCommon<>( OmsConstant.SuccessCodeEnum.SuccessCode.value(), OmsConstant.SuccessCodeEnum.SuccessCode.desc());
	}
}